$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/sysrotationchart/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true , hidden:true},
			{ label: '轮播图的指示点', name: 'indicatordots', index: 'indicatorDots', width: 80 }, 			
			{ label: '是否自动轮播', name: 'autoplay', index: 'autoplay', width: 80 }, 			
			{ label: '轮播图的间隔时间', name: 'intervalTimelong', index: 'interval_timeLong', width: 80 }, 			
			{ label: '滑动时间', name: 'duration', index: 'duration', width: 80 }, 			
			{ label: '图片地址url', name: 'url', index: 'url', width: 80 , hidden:true}, 			
			{ label: '点击路由页面地址', name: 'link', index: 'link', width: 80 , hidden:true}, 			
			{ label: '轮播图的名称', name: 'names', index: 'names', width: 80 }, 			
			{ label: '存储轮播图的名字', name: 'nameAlias', index: 'name_alias', width: 80 }, 			
			{ label: '创建人id', name: 'userId', index: 'user_id', width: 80 , hidden:true}, 			
			{ label: '状态', name: 'lbStatus', index: 'lb_status',width: 40 , formatter: function(value, options, row){
				return value === 1 ? 
						'<span class="label label-danger" value="1">禁用</span>' : 
						'<span class="label label-success" value="0">正常</span>';
			}},	 			
			{ label: '部门ID', name: 'deptId', index: 'dept_id', width: 80 , hidden:true}, 			
			{ label: '创建时间', name: 'createTime', index: 'create_time', width: 85 , formatter:function(value,options,row){
                return new Date(value).Format('yyyy-MM-dd HH:mm:ss');}},			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "rotationchart.list",
            page: "rotationchart.pageNum",
            total: "rotationchart.pages",
            records: "rotationchart.total"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		sysRotationchart: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.sysRotationchart = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.sysRotationchart.id == null ? "sys/sysrotationchart/save" : "sys/sysrotationchart/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.sysRotationchart),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "sys/sysrotationchart/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "sys/sysrotationchart/info/"+id, function(r){
                vm.sysRotationchart = r.sysRotationchart;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});

Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "H+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}